package com.tmbb.hntt.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tmbb.hntt.dto.NeroHate;
import com.tmbb.hntt.service.NeroHateService;

/**
 * @author Shenba
 *
 */
@Controller
@RequestMapping("/NeroHate")
public class NeroHateController {
	
	private NeroHateService NeroHateService = null;
	
	/**
	 * @param model
	 * @return
	 */
	@RequestMapping("/load.do")
	public String load(Model model) {
		NeroHate NeroHate = new NeroHate();
		NeroHate.setNeroHates(NeroHateService.getNeroHates());
		model.addAttribute("NeroHate", NeroHate);
		return "NeroHate";
	}
	
	/**
	 * @param model
	 * @return
	 */
	@RequestMapping("/getNeroHates.do")
	public @ResponseBody List<NeroHate> getNeroHates(Model model) {
		return NeroHateService.getNeroHates();
	}
	
	/**
	 * @param model
	 * @return
	 */
	@RequestMapping("/save.do")
	public String save(Model model, NeroHate NeroHate) {
		NeroHateService.save(NeroHate);
		return "redirect:load.do";
	}
	
	/**
	 * @param model
	 * @return
	 */
	@RequestMapping("/delete.do")
	public String delete(Model model, NeroHate NeroHate) {
		NeroHateService.delete(NeroHate);
		return "redirect:load.do";
	}
	
	/**
	 * @param model
	 * @param NeroHate
	 * @return
	 */
	@RequestMapping("/add.do")
	public String addNewRow(Model model, NeroHate neroHate) {
		List<NeroHate> neroHates = neroHate.getNeroHates();
		neroHates.add(new NeroHate());
		neroHate.setNeroHates(neroHates);
		model.addAttribute("neroHate", neroHate);
		return "nerohate";
	}
	
	/**
	 * @param NeroHateService the NeroHateService to set
	 */
	@Autowired
	public void setNeroHateService(NeroHateService NeroHateService) {
		this.NeroHateService = NeroHateService;
	}
}
